<?php
class Home_Model extends CI_Model {
	protected $table_name = '';
	
	//const GETCARARTICLE_STMT = 'CALL spGetArticlesForHomepage(?, ?)';
	const GETCARARTICLE_STMT = "SELECT * FROM tt_cararticle_tt WHERE article_id > ? LIMIT ?";
	const GETCARLASTESTARTICLE_STMT = "SELECT * FROM tt_cararticle_tt ORDER BY article_id DESC LIMIT ?, ?";
	const COUNTARTICLE_STMT = 'SELECT COUNT(*) as total FROM tt_cararticle_tt';
	
	public function __construct() {
		$this->load->database();
	}
	
	/*
		Functdion to retrieve articles for home page
	*/
	public function get_articles($page, $limit) {
		$params = array($page * $limit, $limit);
		$query = $this->db->query(self::GETCARARTICLE_STMT, $params);
		$result = $query->result_array();
		return $result;	
	}
	
	public function get_lastest_articles($page, $limit, $max_page) {
		$params = array($page * $limit, $limit);
		$query = $this->db->query(self::GETCARLASTESTARTICLE_STMT, $params);
		$result = $query->result_array();
		return $result;	
	}
	
	public function count() {
		$query = $this->db->query(self::COUNTARTICLE_STMT);
		$result = $query->row_array();
		return $result['total'];
	}
}
?>